package com.yangchao.webflux.projectreactor;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import org.slf4j.Logger;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.io.IOException;
import java.time.Duration;
import java.util.function.Consumer;

public class MonoTest {

    static Logger logger = org.slf4j.LoggerFactory.getLogger(MonoTest.class);


    @Test
    @DisplayName("mono测试1")
    public void testMono01() {
        Mono<Object> empty = Mono.empty();
        empty.subscribe(new Subscriber<Object>() {
                            private Subscription subscription;

                            @Override
                            public void onSubscribe(Subscription subscription) {
                                this.subscription = subscription;
                                this.subscription.request(1);

                            }

                            @Override
                            public void onNext(Object o) {
                                logger.info("subscriber1 {}", o);
                                this.subscription.request(1);
                            }

                            @Override
                            public void onError(Throwable throwable) {


                            }

                            @Override
                            public void onComplete() {
                                logger.info("subscriber1 complete");
                            }

                        }

        );
    }
}
